/*
 * MvcProgress.java
 *
 * Created on 21 de septiembre de 2009, 06:51 PM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package com.nextel.ui.custom;

import com.nextel.ui.OAnimation;
import com.nextel.ui.OCompositeScreen;
import com.nextel.ui.OImage;
import com.nextel.ui.OLabel;
import com.nextel.ui.OUILook;
import java.io.IOException;
import javax.microedition.lcdui.Graphics;


/**
 *
 * @author eespinoza
 */
public class OProgress  {
    
    private String[] images;
    private OCompositeScreen formulario;
    private OLabel etiquetaSuperior, etiquetaInferior;
    
    
    public void setEtiquetaSuperior(String cade){
        etiquetaSuperior.setLabel(cade);
    }
    
    public void setEtiquetaInferior(String cade){
        etiquetaInferior.setLabel(cade);
    }
    
    
//
    
    public OCompositeScreen showScreen(String imagenInicio, String imagenAdicional ) {
        try{
            
            int y=0;
            
            formulario = new OCompositeScreen( "Processing ...", OUILook.PLAIN_SMALL_TITLE, 2 );
            formulario.limpiarFormulario = false;
            images = new String[2];
            images[0] = imagenInicio;
//            images[1] = imagenFinal;
            images[1] = imagenAdicional;
            
            if(images[1] != null){
                formulario.add(new OImage(images[1]), 0, ++y, Graphics.LEFT );
            }
            
            etiquetaSuperior = new OLabel("Processing..", OUILook.PLAIN_SMALL_TEXT );
            formulario.add( etiquetaSuperior, 1, y, Graphics.HCENTER| Graphics.VCENTER);
            
            
            
            formulario.add( new OAnimation(images, 90), 0, //90
                    ++y, Graphics.LEFT );
            
            etiquetaInferior = new OLabel("", OUILook.PLAIN_SMALL_TEXT,formulario.getWidth() );
            formulario.add( etiquetaInferior, 0, ++y, Graphics.LEFT );
            
        }catch(IOException e){
            e.printStackTrace();
        }
        return formulario;
        
    }
    
    public void destroy( ){

//        if(formulario != null){
//            formulario.clearAll();
//            formulario = null;
//
//        }
        
        
//        System.out.println("destroy");
        if(formulario != null){
            etiquetaSuperior=null;
            etiquetaInferior=null;
            
            images = null;
            //limpia todo el formulario
            formulario.limpiarFormulario = true;
            formulario = null;

        }
 
//        System.gc();
    }
    
    
    
}
